home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / applets / dance / classes / mexbutto.jav < prev    next >
Encoding:
Text File  |  1995-09-12  |  2.0 KB  |  94 lines

  1. /*-
  2.  * Copyright (c) 1995 by Georg Hessmann.
  3.  * All Right Reserved.
  4.  *
  5.  * MEXButtonList.java    1.0f 25.08f.95
  6.  *
  7.  */
  8.  
  9. import java.awt.Font;
  10.  
  11. import Button;
  12.  
  13. /**
  14.  * MEXButtonList is a header for a group of mutual
  15.  * exclusive buttons of type MEXButton.
  16.  *
  17.  * @see MEXButton
  18.  *
  19.  * @version 1.0f 25 Aug 1995
  20.  * @author Georg Heßmann
  21.  */
  22.  
  23. class MEXButtonList {
  24.  
  25.   MEXButton    List;
  26.   Font        choFont;
  27.  
  28.   /**
  29.    * Create the MEXButton list header.
  30.    * @param fnt font used for the selected element
  31.    */
  32.   public MEXButtonList(Font fnt)
  33.   {
  34.     List    = null;
  35.     choFont = fnt;
  36.   }
  37.  
  38.   /**
  39.    * Insert a new MEXButton into the list of mutual exclusive buttons.
  40.    * @param bnum id number
  41.    * @param l label
  42.    * @param x x-ccordinate of the button
  43.    * @param y y-coordinate of the button
  44.    * @param w the size().width
  45.    * @param h the size().height
  46.    * @param f the font used for the not selected buttons
  47.    */
  48.   public void NewMEXButton(int bnum, String l, int x, int y, int w, int h, Font f)
  49.   {
  50.     List = new MEXButton(this, List, bnum, l, x, y, w, h, f, choFont);
  51.   }
  52.  
  53.   /**
  54.    * Select MEXButton with given id-number.
  55.    *
  56.    * @return Returns, if something has changed and an repaint() is needed.
  57.    */
  58.   public boolean SetChoosedNum(int num)
  59.   {
  60.     MEXButton lst   = List;
  61.     boolean changed = false;
  62.     
  63.     while (lst != null) {
  64.       if (lst.IsChoosed() && lst.GetNum() != num) {
  65.     lst.ClearChoosed();
  66.     changed = true;
  67.       }
  68.       if (!lst.IsChoosed() && lst.GetNum() == num) {
  69.     lst.SetChoosed();
  70.     changed = true;
  71.       }
  72.       lst = lst.NextMEX();
  73.     }
  74.     return changed;
  75.   }
  76.  
  77.   /**
  78.    * @return id-number of the selected button
  79.    */
  80.   public int GetChoosedNum()
  81.   {
  82.     MEXButton lst = List;
  83.     MEXButton cho = null;
  84.     
  85.     while (lst != null && cho == null) {
  86.       if (lst.IsChoosed()) cho = lst;
  87.       lst = lst.NextMEX();
  88.     }
  89.  
  90.     return (cho != null) ? cho.GetNum() : -1;
  91.   }
  92. }
  93.  
  94.